<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.lgx.common.web.Constants,com.lgx.right.entity.User" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	/* User user = (User) request.getSession().getAttribute(Constants.LOGIN_USER);   //获取到当前登录人对象  */
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/head.jsp"></jsp:include>
	<script type="text/javascript">
	
		//保存信息
		function save(){
			
			$('#saveBtn').attr('disabled','disabled');
			
			var truename = escape(escape($('#truename').val()));         //获取truename值
			var sex = escape(escape($('#sex').val()));                   //获取sex值
			var username = escape(escape($('#username').val()));         //获取username值
			var email = escape(escape($('#email').val()));               //获取email值
			var mobile = escape(escape($('#mobile').val()));             //获取mobile值
			
			if($('#fm').form('validate')){
					//执行ajax操作
					$.ajax({
						  url:path +"/user/update.do?userId="+${onlineUser.id}+"&truename="+truename+"&sex="+sex+"&email="+email+"&username="+username+"&mobile="+mobile,
						  success: function(data) {
							  if(data == "1"){
								    alertBox("操作成功！");
								  	//window.location = path+"/user/userMgr.do";
							   }else{
								   alertBox("操作失败！");
							   } 
						  }
					});
				
			}
		}
		
		
		
		//登录名唯一性验证
		function checkUserNameExists(){
			var username = escape(escape($('#username').val()));         //获取username值
			//执行ajax操作
			$.ajax({
				  url:path +"/user/checkUserNameExists.do?username="+username,
				  success: function(data) {
					  if(data == "1"){
						  return true;
					   }else{
						   alertBox("用户名已存在！");
						   return false;
					   } 
				  }
			});
		}
		
		
		//手机号码唯一性验证
		function checkMobileExists(){
			var mobile = escape(escape($('#mobile').val()));             //获取mobile值
			//执行ajax操作
			$.ajax({
				  url:path +"/user/checkMobileExists.do?mobile="+mobile,
				  success: function(data) {
					  if(data == "1"){
						  return true;
					   }else{
						   alertBox("用户名已存在！");
						   return false;
					   } 
				  }
			});
		}
	</script>
	
	<script type="text/javascript">
		//邮箱验证
		$('#email').validatebox({  
		    required:true  
		});
		//自定义规则
		$.extend($.fn.validatebox.defaults.rules, {  
			chs: {    									  //验证汉子
		        validator: function (value) {
		            return /^[\u0391-\uFFE5]+$/.test(value);
		        },
		        message: '只能输入汉字'
		    },
		    mobile:{                                      //手机号码长度必须只能为11个，不能再某些数字之间
		    	validator: function (value) {
		            return /^1[3|4|5|8][0-9]\d{4,8}$/.test(value) ;
		        },
		        message: '输入正确的手机号码!'
		    },
		    checkUserNameExists:{
		    	validator: function (value) {
					return /^[\w]+$/.test(value);
		    	},
		    	message:'只能数字、字母、下划线组成!'
		    }
		});
		
		
	</script>
  </head>
  
  <body>
   <div class="right">
	<div class="ri_main">
	<form id="form">
		<table width="90%" border="0" cellspacing="1" cellpadding="8" style="background:#d9d9d9;">
		  <tr>
		    <td width="15%" align="right" bgcolor="#FFFFFF">姓&nbsp;&nbsp;&nbsp;名</td>
		    <td width="40%" bgcolor="#FFFFFF" align="left"><label for="textfield"></label>
		      <input validType="chs" id="truename" name="truename" class="easyui-validatebox" required="true" style="width:200px;" value="${onlineUser != null?onlineUser.truename:'' }" />
		    </td>
		  </tr>
		  <tr>
		  	<td width="15%" align="right" bgcolor="#FFFFFF">性&nbsp;&nbsp;&nbsp;别</td>
		    <td width="30%" align="left" bgcolor="#FFFFFF">
		    	<select id="sex" name="sex">
		    		<c:forEach var="dict" items="${sexTypes}">
		    			<c:choose>
		    				<c:when test="${onlineUser != null && dict.code == onlineUser.sex}">
		    					<option value="${dict.code }" selected="selected"> ${dict.name } </option>
		    				</c:when>
		    				<c:otherwise>
		    					<option value="${dict.code }"> ${dict.name } </option>
		    				</c:otherwise>
		    			</c:choose>
		    		</c:forEach>
		    	</select>
		    </td>
		  </tr>
		  <tr>
		    <td align="right" bgcolor="#FFFFFF">登 陆 名</td>
		    <td bgcolor="#FFFFFF" align="left">
		    	<input onblur="checkUserNameExists()" id="username" name="username" class="easyui-validatebox" required="true" style="width:200px;" value="${onlineUser != null?onlineUser.username:'' }" />
		    </td>
		  </tr>
		  <tr>
		    <td align="right" bgcolor="#FFFFFF">邮&nbsp;&nbsp;&nbsp;箱</td>
		    <td bgcolor="#FFFFFF" colspan="3" align="left">
		    	<input validType="email" id="email" name="email" class="easyui-validatebox" required="true" style="width:200px;" value="${onlineUser != null?onlineUser.email:'' }" />
		    </td>
		  </tr>
		  <tr>
		    <td align="right" bgcolor="#FFFFFF">手机号码</td>
		    <td bgcolor="#FFFFFF" colspan="3" align="left">
		    	<input validType="mobile" onblur="checkMobileExists()" id="mobile" name="mobile" class="easyui-validatebox" required="true" style="width:200px;" value="${onlineUser != null?onlineUser.mobile:'' }" />
		    </td>
		  </tr>
		  <tr>
		    <td bgcolor="#FFFFFF" colspan="2" align="center">
		    	<a href="javascript:void(0);" id="saveBtn" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">修改</a>
		    </td>
		  </tr>
		</table>
	</form>
	</div>
	</div>
  </body>
</html>
